﻿// WF核心庫 create by alan 2013.04.25
var Core = window.Core || {};
window.TOP = parent.window;
Core.frag = {};
Core.init = function()
{
    jQuery.ajax({
			type: 'GET',
			url: "inc/js/xml/html.xml",
			async: false,
			dataType: 'xml',
			cache: false,
			error: TOP.Core.AJAX.Error,
			success: function(xml) 
			{
				$(xml).find("html").each(function() 
				{
					var pageId = $(this).attr("id");
					if (pageId) TOP.Core.frag[pageId] = $(this).text();
				});				
				$("body").append(TOP.Core.frag["other"]);
			}
		})
    //初始化頁面UI
	initUI();
};
Core.AJAX = 
{
    Error: function(xhr, ajaxOptions, thrownError) 
    {
        alert(thrownError);
    },
    Loadding: function(option)
    {
        
    },
    Post: function(option) {
        var result;
        var op = $.extend({
            type: "POST",
            async: true,
            dataType: "json",
            cache: false,
            url: "post.ashx",
            timeout: 50000,
            contentType: "application/x-www-form-urlencoded",
            beforeSend: function(){$("#progressBar").show();},
            complete: function(){$("#progressBar").hide();},
            error: TOP.Core.AJAX.Error,
            success: function(res) {
                result = res;
                if (op.fn != null) {
                    op.fn.apply(this, [res])
                }
            }
        },option);
        jQuery.ajax(op);
        return result
    }  
};
Core.Form = 
{
    complete:function(id)
    {
        $(id).remove();
    },
    openUrl:function(url, $content, options)
    {
        var isdialog = eval(options.isdialog || "false");
        var htmldivload = TOP.Core.frag["iframeLoadding"].replaceAll("{ifrdivloadclass}", "iframeload").replaceAll("{ifrdivid}", "ifr_div_"+options.id).replaceAll("{height}", $content.height());        
		var htmliframe = TOP.Core.frag["iframeFrag"].replaceAll("{url}", url).replaceAll("{ifrid}", "ifr_"+options.id).replaceAll("{ifrdivid}", "ifr_div_"+options.id);
		if (isdialog)
		    htmliframe = htmliframe.replaceAll("{class}", "dialogiFrameStyle");
		$content.html(htmldivload + htmliframe);
		WinSize();
    }
};

var Message = window.Message || {};
Message = 
{    
    alert: function(msg)
    {
        bootbox.alert(msg)
    },
    confirm: function(msg,fn)
    {
        bootbox.confirm(msg, function(result) 
        {
            if(result && fn != null)
                fn.apply(this);
        });
    },
    prompt:function(msg,fn)
    {
        bootbox.prompt(msg, function(result) 
        {                
            if(fn != null)
                fn.apply(this,[result]);
        })
    },
    ok:function(msg)
    {
        $.gritter.add({
		        color: "#468847",
			    text:	'<i class="icon icon-white icon-check"></i>'+msg,
			    sticky: false
		    });	
    },
    warn:function(msg)
    {
        $.gritter.add({
		        color: "#F89406",
			    text:	'<i class="icon icon-white icon-notice"></i>'+msg,
			    sticky: false
		    });	
    },
    error:function(msg)
    {
        $.gritter.add({
		        color: "#F74D4D",
			    text:	'<i class="icon icon-white icon-close"></i>'+msg,
			    sticky: false
		    });	
    }
};
         
